/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.towers.projectils;

import com.jme3.asset.AssetManager;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Sphere;
import elementsDefense.enemies.BasicEnemy;
import elementsDefense.towers.Tower;

/**
 *
 * @author Ricardo
 */
public class IceBlast extends Projectil{
    
    Geometry ball;
    Material matBlue;
    ParticleEmitter ice;

    public IceBlast(AssetManager assetManager, Node node, Tower source) {
        this.source = source;
        this.assetManager = assetManager;
        this.node =node;
        this.damage = 10;
        this.slow = 0.5f;
        
        ball = new Geometry("ball", new Sphere(5, 5, 0.05f));
        matBlue = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matBlue.setColor("Color", ColorRGBA.Red);
        ball.setMaterial(matBlue);
        
        
        ice = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 20);
        Material mat_red = new Material(assetManager, 
                "Common/MatDefs/Misc/Particle.j3md");
        mat_red.setTexture("Texture", assetManager.loadTexture(
                "Textures/flame.png"));
        ice.setMaterial(mat_red);
        ice.setImagesX(2); 
        ice.setImagesY(2); // 2x2 texture animation
        ice.setEndColor(  new ColorRGBA(0f, 0f, 1f, 1f));   // red
        ice.setStartColor(new ColorRGBA(1f, 1f, 1f, 0.5f)); // yellow
        ice.setStartSize(0.2f);
        ice.setEndSize(0.4f);
        ice.setGravity(0, -1, 0);
        ice.setLowLife(0.4f);
        ice.setRotateSpeed(0.4f);
        ice.setHighLife(0.8f);
        ice.setParticlesPerSec(0);
        ice.getParticleInfluencer().setVelocityVariation(0.3f);
        node.attachChild(ice);
    }
    
    public void shootAt(BasicEnemy target){
        this.target = target;
        if(homing==null){
            homing = new HomingControl(source,target,this,0.05f);
            ice.addControl(homing);
        }else{
            homing.reset(source, target, this, 0.05f);
        }
        ice.setParticlesPerSec(20);
    }
    
    public void hit(){
        ice.setParticlesPerSec(0);
        target.hit(this);
    }
   
}
